package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 查询所有频道
 */
@RestController
@RequestMapping("/api/v1/channel")
public class ChannelController {

    @Autowired
    private WmChannelService wmChannelService;

    @GetMapping("/channels")
    public ResponseResult findAll() {
        return wmChannelService.findAll();
    }

    /**
     * 新增频道
     *
     * @param wmChannel 频道信息
     * @return 返回结果
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannel wmChannel) {
        return wmChannelService.channelSave(wmChannel);
    }


    /**
     * 分页查询频道列表
     *
     * @param dto 查询条件
     * @return 返回结果
     */
    @PostMapping("/list")
    public PageResponseResult list(@RequestBody ChannelDto dto) {
        return wmChannelService.list(dto);
    }

    /**
     * 修改频道信息
     *
     * @param wmChannel 频道信息
     * @return 返回结果
     */
    @PostMapping("/update")
    public ResponseResult updatae(@RequestBody WmChannel wmChannel) {
        return wmChannelService.update(wmChannel);
    }

    /**
     * 删除频道
     *
     * @param id 频道id
     * @return 返回结果
     */
    @GetMapping("/del/{id}")
    public ResponseResult del(@PathVariable Integer id) {
        return wmChannelService.del(id);
    }


}
